#!/bin/sh
[ "$ACTION" = "ifdown" ] &&	pppconnectcheck &

wanselect=$(uci get syncdial.config.wanselect)
[ "$(uci get syncdial.config.dial_type)" = "2" ] && {
	wanselect2=$(uci get syncdial.config.wanselect2)
}

[ "$(uci get syncdial.config.enabled)" = "1" ] && \
	[ "$(uci get syncdial.config.old_frame)" = "1" ] && \
	[ "$DEVICE" = "$(uci get network.$wanselect.ifname)" ] && \
	[ "$ACTION" = "ifup" ] && {
	ifname=$(uci get network.$wanselect.ifname)
	wannum=$(uci get syncdial.config.wannum)
	for i in $(seq 1 $wannum)
	do
		[ -d /sys/class/net/macvlan$i ] || {
			ip link add link $ifname name macvlan$i type macvlan
			ifconfig macvlan$i hw ether $(echo $(cat /sys/class/net/$ifname/address|awk -F ":" '{print $1":"$2":"$3":"$4":"$5":" }')$(echo "" | awk -F ":" '{printf("%X\n", 16+i);}' i=$i))
			ifconfig macvlan$i up
		}
	done

	[ "$(uci get syncdial.config.dial_type)" = "2" ] && {
	ifname2=$(uci get network.$wanselect2.ifname)
	wannum2=$(uci get syncdial.config.wannum2)
	for i in $(seq 1 $wannum2)
	do
		[ -d /sys/class/net/macvlan$(($wannum+$i)) ] || {
			ip link add link $ifname2 name macvlan$(($wannum+$i)) type macvlan
			ifconfig macvlan$(($wannum+$i)) hw ether $(echo $(cat /sys/class/net/$ifname2/address|awk -F ":" '{print $1":"$2":"$3":"$4":"$5":" }')$(echo "" | awk -F ":" '{printf("%X\n", 16+i);}' i=$i))
			ifconfig macvlan$(($wannum+$i)) up
		}
	done
	}
}
